#include<stdio.h>
#include<stdlib.h>
#define SIZE 5

struct Student_type
{
    char name[10];
    int num;
    char sex;
    int grade;
}stud[SIZE];

void sort(struct Student_type *stu,int count)
{
    struct Student_type t;
    int i,j,k;
    for(i=0;i<count-1;i++){
        k=i;
        for(j=i+1;j<count;j++)
        if(stud[j].grade>=stud[k].grade)  k=j;
        if(k!=i){
            t=stud[i];
            stud[i]=stud[k];
            stud[k]=t;
        }
    }
}

void main()
{
    FILE *fp1,*fp2,*fp3;
    int i;
    int count=0;
    printf("输入姓名 学号 性别 成绩：\n");
    for(i=0;i<SIZE;i++)  scanf("%s %d %c %d",stud[i].name,&stud[i].num,&stud[i].age,&stud[i].grade);
    if((fp1=fopen("\\TEMP\\stu1.dat","wb"))==NULL){
        printf("Cannot open file!\n");
        exit(0);
    }
    if((fp2=fopen("\\TEMP\\stu1.dat","wb"))==NULL){
        printf("Cannot open file!\n");
        exit(0);
    }
    if((fp3=fopen("\\TEMP\\stu1.dat","wb"))==NULL){
        printf("Cannot open file!\n");
        exit(0);
    }
    for(i=0;i<SIZE;i++)
    {
        if(fwrite(&stud[i],sizeof(struct Student_type),1,fp2)!=1){
            printf("File write error\n");
            exit(0);
        }
    }
}